package com.ruoyi.project.courseuser.courseuser.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.courseuser.courseuser.domain.BCourseUser;
import com.ruoyi.project.courseuser.courseuser.service.IBCourseUserService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户报名活动课程Controller
 * 
 * @author ruoyi
 * @date 2024-01-24
 */
@Controller
@RequestMapping("/courseuser/courseuser")
public class BCourseUserController extends BaseController
{
    private String prefix = "courseuser/courseuser";

    @Autowired
    private IBCourseUserService bCourseUserService;

    @RequiresPermissions("courseuser:courseuser:view")
    @GetMapping()
    public String courseuser()
    {
        return prefix + "/courseuser";
    }

    /**
     * 查询用户报名活动课程列表
     */
    @RequiresPermissions("courseuser:courseuser:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BCourseUser bCourseUser)
    {
        startPage();
        List<BCourseUser> list = bCourseUserService.selectBCourseUserList(bCourseUser);
        return getDataTable(list);
    }

    /**
     * 导出用户报名活动课程列表
     */
    @RequiresPermissions("courseuser:courseuser:export")
    @Log(title = "用户报名活动课程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BCourseUser bCourseUser)
    {
        List<BCourseUser> list = bCourseUserService.selectBCourseUserList(bCourseUser);
        ExcelUtil<BCourseUser> util = new ExcelUtil<BCourseUser>(BCourseUser.class);
        return util.exportExcel(list, "用户报名活动课程数据");
    }

    /**
     * 新增用户报名活动课程
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户报名活动课程
     */
    @RequiresPermissions("courseuser:courseuser:add")
    @Log(title = "用户报名活动课程", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BCourseUser bCourseUser)
    {
        return toAjax(bCourseUserService.insertBCourseUser(bCourseUser));
    }

    /**
     * 修改用户报名活动课程
     */
    @RequiresPermissions("courseuser:courseuser:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BCourseUser bCourseUser = bCourseUserService.selectBCourseUserById(id);
        mmap.put("bCourseUser", bCourseUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户报名活动课程
     */
    @RequiresPermissions("courseuser:courseuser:edit")
    @Log(title = "用户报名活动课程", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BCourseUser bCourseUser)
    {
        return toAjax(bCourseUserService.updateBCourseUser(bCourseUser));
    }

    /**
     * 删除用户报名活动课程
     */
    @RequiresPermissions("courseuser:courseuser:remove")
    @Log(title = "用户报名活动课程", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bCourseUserService.deleteBCourseUserByIds(ids));
    }
}
